<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>账号创建</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="public/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>账号注册</legend>
</fieldset>

<form class="layui-form" action="" lay-filter="example">

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*</span>登录账号</label>
        <div class="layui-input-block">
            <input type="text" name="account" lay-verify="account" autocomplete="off" placeholder="请输入注册账号(账号一般用电话或者姓名全拼)" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*</span>密码</label>
        <div class="layui-input-block">
            <input type="text" name="pwd" lay-verify="pwd" autocomplete="off" placeholder="请输入密码" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*</span>真实姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="请输入真实姓名" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*</span>电话</label>
        <div class="layui-input-block">
            <input type="text" name="phone" lay-verify="phone" autocomplete="off" placeholder="请输入电话" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*</span>地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" lay-verify="address" autocomplete="off" placeholder="请输入地址" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn layui-btn-normal" id="LAY-component-form-getval" lay-submit>立即注册</button>
        </div>
    </div>
</form>
<script src="public/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });



        //自定义验证规则
        form.verify({
            account: function(value){
                if(value.replace(/\s+/g,"").length == "" || value.replace(/\s+/g,"").length == null ){
                    return '请填写姓名！';
                }
            },
            pwd: function(value){
                if(value.replace(/\s+/g,"").length == "" || value.replace(/\s+/g,"").length == null ){
                    return '请填写密码！';
                }
            },
            address: function(value){
                if(value.replace(/\s+/g,"").length == "" || value.replace(/\s+/g,"").length == null ){
                    return '请填写地址！';
                }
            },
            phone: function(value){
                if(value.replace(/\s+/g,"").length == "" || value.replace(/\s+/g,"").length == null ){
                    return '请填写电话！';
                }
            }

        });



//        表单取值
        layui.$('#LAY-component-form-getval').on('click', function(){
            var data = form.val('example');
            console.log(JSON.stringify(data))
        });

    });
</script>

</body>
</html>